(function($, owner) {
    /**
     * 清除当前状态
     **/
    owner.removeState = function(){
        localStorage.removeItem('$state');
    }

    /**
     * 获取当前状态
     **/
    owner.getState = function() {
        var stateText = localStorage.getItem('$state') || "{}";
        return JSON.parse(stateText);
    };

    /**
     * 设置当前状态
     **/
    owner.setState = function(state) {
        state = state || {};
        localStorage.setItem('$state', JSON.stringify(state));
    };

}(mui, window.app = {}));

/**
 * 默认地地址
 */
function  getDefault(){
    setTimeout(function () {
        var selected = {
            realname:"李一个",
            phone:"13490787878",
            address:"北京 北海",
        }

        mui("#name")[0].innerHTML = selected.realname;
        mui("#phone")[0].innerHTML = selected.phone;
        mui("#address")[0].innerHTML = selected.address;

    },1000)
}

mui.ready(function () {

    // 清除当前状态
    app.removeState();

    // 收货信息
    var selected = localStorage.getItem("selected"); // 已经选择的地址
    if(selected){
        selected = JSON.parse(selected);
        if(selected){
            mui("#name")[0].innerHTML = selected.realname;
            mui("#phone")[0].innerHTML = selected.phone;
            mui("#address")[0].innerHTML = selected.address;
        }
    }else{
        // 默认地地址
        getDefault();
    }

    // 选择
    mui(".mui-content").on("tap",".address",function () {
        console.log("xxxxxx")
        app.setState({"doSelect":"true"});// 设置去地址列表选择地十标识
        location.href = "../../pages/address/address.html";
    })

    // 提交
    mui("#bott").on("tap","#submit_m",function () {
        console.log("333")
        location.href = "../../pages/machine/machine_pay.html";
    })
});